package org.jazz.web.controller;

import java.lang.reflect.Method;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.jazz.basic.Action;
import org.jazz.basic.ModelAndView;

public class MultiController implements Action{

	protected static Logger logger = Logger.getLogger("Controller");

	public MultiController() {
		super();
	}

	public ModelAndView execute(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String methodName = request.getParameter("method");
		if (methodName == null){
			methodName = "doJob";
		}
		Method method = this.getClass().getMethod(methodName, HttpServletRequest.class, HttpServletResponse.class);
		logger.info(this);
		logger.info(this.getClass());
		logger.info(method);
		
		ModelAndView result = (ModelAndView) method.invoke(this, request, response);
		return result;
	}

	public ModelAndView doJob(HttpServletRequest request, HttpServletResponse response) throws Exception {
		return new ModelAndView("/WEB-INF/index.jsp");
	}
}